package com.tb.tbv1productservice.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tb.v1.api.product.IProductService;
import com.tb.v1.api.vo.ProductVo;
import com.tb.v1.common.base.BaseServiceImpl;
import com.tb.v1.common.base.IBaseDao;
import com.tb.v1.entity.TProduct;
import com.tb.v1.mapper.TProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: tangBin
 * @Date: 2020/6/5 0005 10:35
 * @Description:
 */
@Component
@Service
public class ProductService extends BaseServiceImpl<TProduct> implements IProductService {
    @Autowired
    private TProductMapper productMapper;
    @Override
    public IBaseDao<TProduct> getBaseDao() {
        return productMapper;
    }
    @Transactional
    @Override
    public PageInfo<TProduct> page(Integer pageIndex, Integer pageSize) {
        PageHelper.startPage(pageIndex,pageSize);
        List<TProduct> list = productMapper.getAll();
        PageInfo<TProduct> pageInfo = new PageInfo<>(list,4);
        return pageInfo;
    }

    @Override
    public int add(ProductVo productVo) {
        int id = productMapper.saveEntity(productVo.getTProduct());
        return id;
    }
}
